/** 已经经过边缘校验 ,一个单元有两个元素*/
const get = (m: Uint32Array, x: u16, y: u16, width: u16): u32[] => {
    const init = (y * width + x) * 2;
    return [m[init], m[init + 1]];
};
export const Uint32Array_ID = idof<Uint32Array>();
/** 获取填充位置的函数 */
export function getColorFlood(
    m: Uint32Array,
    x: u16,
    y: u16,
    width: u16,
    height: u16
): u16[][] {
    /** 颜色标识 */
    const sampleTag = get(m, x, y, width);
    const queue: u16[][] = [];
    const col = new Set<string>();

    const result: u16[][] = [];
    // 把第一个放在队列
    queue.push([x, y]);
    while (queue.length) {
        const node = queue.shift();
        x = node[0];
        y = node[1];
        const tag = [x, y].join();
        if (!col.has(tag)) {
            col.add(tag);
            const Sample = get(m, x, y, width);

            // 如果该点的透明度为 0 ，那么直接填充
            if (
                Sample[1] === 0 ||
                (Sample[0] === sampleTag[0] && Sample[1] === sampleTag[1])
            ) {
                result.push([x, y]);
                // 边界守护
                if (y !== height - 1) queue.push([x, y + 1]);
                if (x !== width - 1) queue.push([x + 1, y]);
                if (y !== 0) queue.push([x, y - 1]);
                if (x !== 0) queue.push([x - 1, y]);
            }
        }
    }
    return result;
}
